window.onload = function () {
    // 创建地图实例
    var map = new BMap.Map("container");
    var pointFrist={
        lng:"",
        lat:""
    }
    //起始地图坐标
    var point = new BMap.Point(118.756376, 32.052573);
    map.centerAndZoom(point, 1);
    // map.addControl(new BMap.ScaleControl());
    // map.addControl(new BMap.OverviewMapControl());
    // map.addControl(new BMap.MapTypeControl());
    map.enableScrollWheelZoom();   //启用滚轮放大缩小，默认禁用
    map.enableContinuousZoom();    //启用地图惯性拖拽，默认禁用
    //单击获取点击的经纬度
    map.addEventListener("click",function(e){

        alert(e.point.lng + "," + e.point.lat);

        var myP1 = new BMap.Point(pointFrist.lng,pointFrist.lat);    //起点   (上一次终点作为起点)
        var myP2 = new BMap.Point(e.point.lng,e.point.lat);    //终点
        pointFrist.lng=e.point.lng;
        pointFrist.lat=e.point.lat;
        driving.search({title: '杭州', point:myP1}, {title: '北京', point:myP2});    //显示一条公交线路
    });

    // 创建标注
    var marker = new BMap.Marker(point);
    marker.enableDragging();



    var routePolicy = [BMAP_DRIVING_POLICY_LEAST_TIME,BMAP_DRIVING_POLICY_LEAST_DISTANCE,BMAP_DRIVING_POLICY_AVOID_HIGHWAYS];
    //驾车路线
    var driving = new BMap.DrivingRoute(map, {
        renderOptions: {
            map: map,
            autoViewport: true
        },
        policy: routePolicy[1],   	//三种驾车策略：最少时间0，最短距离1，避开高速2
    });


    $(function () {
        // var myP1 = new BMap.Point(107.690967,36.913285);    //起点
        // var myP2 = new BMap.Point(107.924374,36.915690);    //终点
        // driving.search({title: '杭州', point:myP1}, {title: '北京', point:myP2});    //显示一条公交线路

        // map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
        // var local = new BMap.LocalSearch(map, {
        //     renderOptions:{map: map}
        // });
        // local.search("杭州 紫荆花路-道路");
    })

}
